<!DOCTYPE html>
<html>


<!-- Mirrored from www.gzsxt.cn/theme/hplus/table_basic.html by HTTrack Website Copier/3.x [XR&CO'2014], Wed, 20 Jan 2016 14:20:01 GMT -->
<head>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">


<title>办公系统 - 基础表格</title>
<meta name="keywords" content="办公系统">
<meta name="description" content="办公系统">

<link rel="shortcut icon" href="favicon.ico">
<link href="css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
<link href="css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
<link href="css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
<link href="css/animate.min.css" rel="stylesheet">
<link href="css/style.min862f.css?v=4.1.0" rel="stylesheet">
<link href="css/plugins/select/bootstrap-select.min.css"
	rel="stylesheet">
<link rel="stylesheet" href="css/plugins/zTreeStyle/zTreeStyle.css" />

</head>

<body class="gray-bg">
	<div class="wrapper2 wrapper-content2 animated fadeInRight">
		<div class="row">
			
			<div class="col-sm">
				<div class="ibox float-e-margins">
					<div class="ibox-title">
						<h5>资源添加</h5>
					</div>
					<div class="ibox-content">
						<form id="updateForm" class="form-horizontal">
							<input type="hidden" name="id"/>
							<div class="form-group">
								<label class="col-sm-4 control-label">菜单资源名称：</label>

								<div class="col-sm-3">
									<input type="text" class="form-control" name="name">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-4 control-label">父菜单：</label>

								<div class="col-sm-3">
									<select name="pid" class="selectpicker form-control  ">
										<!-- <option>Mustard</option>
										<option>Ketchup</option> 
										<option>Relish</option> -->
									</select>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-4 control-label">菜单资源路径：</label>

								<div class="col-sm-3">
									<input type="text" name="url" class="form-control">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-4 control-label">备注：</label>
								<div class="col-sm-3">
									<textarea class="form-control" name="remark"></textarea>
								</div>
							</div>
							<div class="form-group">
								<div class="col-sm-offset-3 col-sm-4">
									<button class="btn btn-sm btn-white" type="button" id="btn">
										<i class="fa fa-save"></i> 保存
									</button>
									<button class="btn btn-sm btn-white" type="reset">
										<i class="fa fa-undo"></i> 重置
									</button>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>

		</div>

	</div>
	<script src="js/jquery.min.js?v=2.1.4"></script>
	<script src="js/bootstrap.min.js?v=3.3.6"></script>
	<script src="js/plugins/select/bootstrap-select.min.js"></script>
	<script src="js/plugins/sweetalert/sweetalert.min.js"></script>
	<script src="js/plugins/ztree/jquery.ztree.core.min.js"></script>
	<script src="js/plugins/ztree/jquery.ztree.exedit.js"></script>
	<script src="js/jquery.serializejson.min.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		
		$(function(){
			
			var str = window.location.search
			//console.log(str)//?id=49
			
			var id = str.substring(str.lastIndexOf("id")+"id".length+1)
			// console.log(id)
			$("input[name='id']").val(id)
			
			$.ajax({
				url:"source/all",
				type:"get",
				dataType:"json",
				async:false,
				success:function(ret){
					if(ret.status){
						$.each(ret.data.items,function(i,source){
							$("select[name='pid']").append('<option value="'+source.id+'">'+source.name+'</option>');
						})
					}
				}
			})
			
			$.ajax({
				url:"source/"+id,
				type:"get",
				dataType:"json",
				async:false,
				success:function(ret){
					if(ret.status){
						$("input[name='name']").val(ret.data.item.name)
						$("input[name='url']").val(ret.data.item.url)
						$("option[value='"+ret.data.item.pid+"']").attr("selected","selected");
						$("textarea[name='remark']").text(ret.data.item.remark)
					}else{
						alert(ret.msg)
					}
				}
			})
			
				
			$("#btn").click(function(){
				var data = $("#updateForm").serializeJSON()

				$.ajax({
					url:"source/update",
					type:"post",
					data:JSON.stringify(data),
					dataType:"json",
					contentType:"application/json",
					success:function(ret){
						if(ret.status){
							window.location.href="list-resources.html";
						}else{
							alert(ret.msg)
						}
					}
				})
				
			})
			
		})
		
	</script>
	
	
</body>


</html>
